﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
public partial class zoushitu_dlt_dlt_chtz : System.Web.UI.Page
{
    protected List<Model.LotteryAnnouncement> arlist = null;
    protected string[] SSQList = null;
    protected string SSQblue = null;
    protected int jinqiCount = 0;
    protected DataTable dtPaperList = new DataTable();
    protected DataTable dtPaperList1 = new DataTable();
    protected Hashtable dt_tiao = new Hashtable();//统计0-9格式
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            jinqiCount = 30;
            bindData(30);
        }
    }
    protected string chk(string num)
    {
        if (int.Parse(num) % 2 == 0)
        {
            return num;
        }
        else
        {
            return "<span class=' f_r'>" + num + "</span>";
        }
    }
    protected string chk_blue(string num)
    {
        if (int.Parse(num) % 2 == 0)
        {
            return "<span class=' f_r' style='color: #0195DF'>" + num + "</span>";
        }
        else
        {
            return "<span class=' f_r'>" + num + "</span>";
        }
    }
    protected void bindData(int maxValue)
    {

        arlist = BLL.LotteryAnnouncement.getDatas(maxValue,2);

        if (arlist != null)
        {
            #region

            dtPaperList.Columns.Add("Id", typeof(int));
            dtPaperList.Columns.Add("Chonghao", typeof(string));
            dtPaperList.Columns.Add("Lianhao", typeof(string));
            dtPaperList.Columns.Add("Hezhi", typeof(string));
            dtPaperList.Columns.Add("Jioubi", typeof(string));
            dtPaperList.Columns.Add("Wuqubi", typeof(string));

            dtPaperList1.Columns.Add("Hezhi0", typeof(string));
            dtPaperList1.Columns.Add("Hezhi1", typeof(string));
            dtPaperList1.Columns.Add("Hezhi2", typeof(string));
            dtPaperList1.Columns.Add("Hezhi3", typeof(string));
            dtPaperList1.Columns.Add("Hezhi4", typeof(string));
            dtPaperList1.Columns.Add("Hezhi5", typeof(string));
            dtPaperList1.Columns.Add("Hezhi6", typeof(string));
            dtPaperList1.Columns.Add("Hezhi7", typeof(string));
            dtPaperList1.Columns.Add("Hezhi8", typeof(string));
            dtPaperList1.Columns.Add("Hezhi9", typeof(string));

            dtPaperList.Columns.Add("201y2", typeof(string));
            dtPaperList.Columns.Add("201y0", typeof(string));
            dtPaperList.Columns.Add("201y1", typeof(string));

            dtPaperList.Columns.Add("c3y0", typeof(string));
            dtPaperList.Columns.Add("c3y1", typeof(string));
            dtPaperList.Columns.Add("c3y2", typeof(string));

            dtPaperList.Columns.Add("c5y0", typeof(string));
            dtPaperList.Columns.Add("c5y1", typeof(string));
            dtPaperList.Columns.Add("c5y2", typeof(string));
            dtPaperList.Columns.Add("c5y3", typeof(string));
            dtPaperList.Columns.Add("c5y4", typeof(string));

            dt_tiao.Add("0", 0);
            dt_tiao.Add("1", 0);
            dt_tiao.Add("2", 0);
            dt_tiao.Add("3", 0);
            dt_tiao.Add("4", 0);
            dt_tiao.Add("5", 0);
            dt_tiao.Add("6", 0);
            dt_tiao.Add("7", 0);
            dt_tiao.Add("8", 0);
            dt_tiao.Add("9", 0);

            dt_tiao.Add("10", 0);
            dt_tiao.Add("11", 0);
            dt_tiao.Add("12", 0);
            dt_tiao.Add("13", 0);
            dt_tiao.Add("14", 0);
            dt_tiao.Add("15", 0);
            dt_tiao.Add("16", 0);
            dt_tiao.Add("17", 0);
            dt_tiao.Add("18", 0);
            dt_tiao.Add("19", 0);
            dt_tiao.Add("20", 0);
            int w0 = 0, w1 = 0, w2 = 0, w3 = 0, w4 = 0, w5 = 0, w6 = 0, w7 = 0, w8 = 0, w9 = 0, w10 = 0, w11 = 0, w12 = 0, w13 = 0, w14 = 0, w15 = 0, w16 = 0, w17 = 0, w18 = 0, w19 = 0, w20 = 0;
            #endregion
            for (int i = 0; i < arlist.Count; i++)
            {
                DataRow newRow = dtPaperList.NewRow();
                DataRow newRow1 = dtPaperList1.NewRow();
                newRow["Id"] = i + 1;
                //重号
                string[] redBall = arlist[i].LotteryNo.Split('+')[0].Split(',');
                string chonghao = "";
                int count = 0;
                int lianhaocout = 0;//连号个数
                int hezhi = 0;//和值
                int jishucount = 0;//奇数个数
                int oushucount = 0;//偶数个数
                int yiqu = 0;//一区个数
                int erqu = 0;//二区个数
                int sanqu = 0;//三区个数
                int siqu = 0;
                int wuqu = 0;

                int y2_201 = 0;
                int y0_201 = 0;
                int y1_201 = 0;
                int y0_c3 = 0;
                int y1_c3 = 0;
                int y2_c3 = 0;
                int y0_c5 = 0;
                int y1_c5 = 0;
                int y2_c5 = 0;
                int y3_c5 = 0;
                int y4_c5 = 0;
                for (int m = 0; m < redBall.Length; m++)
                {
                    //计算条形图中每个数的个数
                    bindTiaoxing(0, int.Parse(redBall[m]));

                    #region 计算重号，连号，和值，奇偶，五区比例
                    if (m < (redBall.Length - 1))
                    {
                        if ((int.Parse(redBall[m]) + 1) == int.Parse(redBall[m + 1]))
                        {
                            lianhaocout++;
                            if ((m < (redBall.Length - 2) && (int.Parse(redBall[m]) + 2) != int.Parse(redBall[m + 2])) || m == (redBall.Length - 2))
                            {
                                lianhaocout++;
                            }
                        }
                    }
                    hezhi += int.Parse(redBall[m]);
                    if (int.Parse(redBall[m]) % 2 == 0)
                    {
                        oushucount++;
                    }
                    else
                    {
                        jishucount++;
                    }
                    if (int.Parse(redBall[m]) > 0 && int.Parse(redBall[m]) <= 7) { yiqu++; }
                    else if (int.Parse(redBall[m]) > 7 && int.Parse(redBall[m]) <= 14) { erqu++; }
                    else if (int.Parse(redBall[m]) > 14 && int.Parse(redBall[m]) <= 21) { sanqu++; }
                    else if (int.Parse(redBall[m]) > 21 && int.Parse(redBall[m]) <= 28) { siqu++; }
                    else if (int.Parse(redBall[m]) > 28 && int.Parse(redBall[m]) <= 35) { wuqu++; }
                    //重号处理
                    if (i== 0)
                    {
                        chonghao = "0";
                    }
                    else
                    {
                        string[] redBallLast = arlist[i-1].LotteryNo.Split('+')[0].Split(',');
                        for (int n = 0; n < redBall.Length; n++)
                        {
                            if (redBall[m] == redBallLast[n])
                            {
                                count++;
                            }
                        }
                    }
                    #endregion

                    #region 尾数计算
                    int data = int.Parse(redBall[m].Substring(redBall[m].Length - 1, 1));
                    for (int j = 0; j < 10; j++)
                    {
                        if (data == j)
                        {
                            string aa = newRow1["Hezhi" + j].ToString();
                            if (aa == "")
                            {
                                newRow1["Hezhi" + j] = "0";
                            }
                            int a = int.Parse(newRow1["Hezhi" + j].ToString());

                            newRow1["Hezhi" + j] = (a + 1).ToString();

                        }
                    }
                    #endregion

                    #region 201
                    int data_201 = int.Parse(redBall[m].Substring(redBall[m].Length - 1, 1));
                    if (data_201 % 3 == 2)
                    {
                        y2_201 = y2_201 + 1;
                    }
                    else if (data_201 % 3 == 0)
                    {
                        y0_201 = y0_201 + 1;
                    }
                    else if (data_201 % 3 == 1)
                    {
                        y1_201 = y1_201 + 1;
                    }
                   
                    #endregion

                    #region 除3
                    if (int.Parse(redBall[m]) % 3 == 0)
                    {
                        y0_c3 = y0_c3 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 3 == 1)
                    {
                        y1_c3 = y1_c3 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 3 == 2)
                    {
                        y2_c3 = y2_c3 + 1;
                    }
                  
                    #endregion


                    #region 除5
                    if (int.Parse(redBall[m]) % 5 == 0)
                    {
                        y0_c5 = y0_c5 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 5 == 1)
                    {
                        y1_c5 = y1_c5 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 5 == 2)
                    {
                        y2_c5 = y2_c5 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 5 == 3)
                    {
                        y3_c5 = y3_c5 + 1;
                    }
                    else if (int.Parse(redBall[m]) % 5 == 4)
                    {
                        y4_c5 = y4_c5 + 1;
                    }
                  
                    #endregion
                }
                w10 = w10 + y2_201;
                w11 = w11 + y0_201;
                w12 = w12 + y1_201;
                w13 = w13 + y0_c3;
                w14 = w14 + y1_c3;
                w15 = w15 + y2_c3;
                w16 = w16 + y0_c5;
                w17 = w17 + y1_c5;
                w18 = w18 + y2_c5;
                w19 = w19 + y3_c5;
                w20 = w20 + y4_c5;
                dtPaperList1.Rows.Add(newRow1);
                chonghao = count.ToString();

                newRow["Chonghao"] = chonghao;
                newRow["Lianhao"] = lianhaocout.ToString();
                newRow["Hezhi"] = hezhi.ToString();
                newRow["Jioubi"] = jishucount + ":" + oushucount;
                newRow["Wuqubi"] = yiqu + ":" + erqu + ":" + sanqu + ":" + siqu + ":" + wuqu;

                newRow["201y2"] = y2_201;
                newRow["201y0"] = y0_201;
                newRow["201y1"] = y1_201;

                newRow["c3y0"] = y0_c3;
                newRow["c3y1"] = y1_c3;
                newRow["c3y2"] = y2_c3;

                newRow["c5y0"] = y0_c5;
                newRow["c5y1"] = y1_c5;
                newRow["c5y2"] = y2_c5;
                newRow["c5y3"] = y3_c5;
                newRow["c5y4"] = y4_c5;
                dtPaperList.Rows.Add(newRow);

               
                #region 尾数条形统计
                string ws0 = dtPaperList1.Rows[i]["Hezhi0"].ToString();
                string ws1 = dtPaperList1.Rows[i]["Hezhi1"].ToString();
                string ws2 = dtPaperList1.Rows[i]["Hezhi2"].ToString();
                string ws3 = dtPaperList1.Rows[i]["Hezhi3"].ToString();
                string ws4 = dtPaperList1.Rows[i]["Hezhi4"].ToString();
                string ws5 = dtPaperList1.Rows[i]["Hezhi5"].ToString();
                string ws6 = dtPaperList1.Rows[i]["Hezhi6"].ToString();
                string ws7 = dtPaperList1.Rows[i]["Hezhi7"].ToString();
                string ws8 = dtPaperList1.Rows[i]["Hezhi8"].ToString();
                string ws9 = dtPaperList1.Rows[i]["Hezhi9"].ToString();

                //string ws10 = dtPaperList.Rows[i]["201y2"].ToString();
                //string ws11 = dtPaperList.Rows[i]["201y0"].ToString();
                //string ws12 = dtPaperList.Rows[i]["201y1"].ToString();
                //string ws13 = dtPaperList.Rows[i]["c3y0"].ToString();
                //string ws14 = dtPaperList.Rows[i]["c3y1"].ToString();
                //string ws15 = dtPaperList.Rows[i]["c3y2"].ToString();
                //string ws16 = dtPaperList.Rows[i]["c5y0"].ToString();
                //string ws17 = dtPaperList.Rows[i]["c5y1"].ToString();
                //string ws18 = dtPaperList.Rows[i]["c5y2"].ToString();
                //string ws19 = dtPaperList.Rows[i]["c5y3"].ToString();
                //string ws20 = dtPaperList.Rows[i]["c5y4"].ToString();
                if (ws0.ToString() != "")
                {
                    if (int.Parse(ws0) > 1)
                    {
                        w0 = w0 + int.Parse(ws0);
                    }
                    else
                    {
                        w0 = w0 + 1;

                    }
                    dt_tiao["0"] = w0;
                }
                if (ws1.ToString() != "")
                {
                    if (int.Parse(ws1) > 1)
                    {
                        w1 = w1 + int.Parse(ws1);
                    }
                    else
                    {
                        w1 = w1 + 1;
                    }
                    dt_tiao["1"] = w1;
                }
                if (ws2.ToString() != "")
                {
                    if (int.Parse(ws2) > 1)
                    {
                        w2 = w2 + int.Parse(ws2);
                    }
                    else
                    {
                        w2 = w2 + 1;
                    }
                    dt_tiao["2"] = w2;
                }
                if (ws3.ToString() != "")
                {
                    if (int.Parse(ws3) > 1)
                    {
                        w3 = w3 + int.Parse(ws3);
                    }
                    else
                    {
                        w3 = w3 + 1;
                    }
                    dt_tiao["3"] = w3;
                }
                if (ws4.ToString() != "")
                {
                    if (int.Parse(ws4) > 1)
                    {
                        w4 = w4 + int.Parse(ws4);
                    }
                    else
                    {
                        w4 = w4 + 1;
                    }
                    dt_tiao["4"] = w4;
                }
                if (ws5.ToString() != "")
                {
                    if (int.Parse(ws5) > 1)
                    {
                        w5 = w5 + int.Parse(ws5);
                    }
                    else
                    {
                        w5 = w5 + 1;
                    }
                    dt_tiao["5"] = w5;
                }
                if (ws6 != "")
                {
                    if (int.Parse(ws6) > 1)
                    {
                        w6 = w6 + int.Parse(ws6);
                    }
                    else
                    {
                        w6 = w6 + 1;
                    }
                    dt_tiao["6"] = w6;
                }
                if (ws7 != "")
                {
                    if (int.Parse(ws7) > 1)
                    {
                        w7 = w7 + int.Parse(ws7);
                    }
                    else
                    {
                        w7 = w7 + 1;
                    }
                    dt_tiao["7"] = w7;
                }
                if (ws8 != "")
                {
                    if (int.Parse(ws8) > 1)
                    {
                        w8 = w8 + int.Parse(ws8);
                    }
                    else
                    {
                        w8 = w8 + 1;
                    }
                    dt_tiao["8"] = w8;
                }
                if (ws9 != "")
                {
                    if (int.Parse(ws9) > 1)
                    {
                        w9 = w9 + int.Parse(ws9);
                    }
                    else
                    {
                        w9 = w9 + 1;
                    }
                    dt_tiao["9"] = w9;
                }
                #endregion

            }
            dt_tiao["10"] = w10;

            dt_tiao["11"] = w11;

            dt_tiao["12"] = w12;

            dt_tiao["13"] = w13;

            dt_tiao["14"] = w14;

            dt_tiao["15"] = w15;

            dt_tiao["16"] = w16;

            dt_tiao["17"] = w17;

            dt_tiao["18"] = w18;

            dt_tiao["19"] = w19;

            dt_tiao["20"] = w20;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        jinqiCount = int.Parse(DropDownList1.SelectedValue);
        bindData(int.Parse(DropDownList1.SelectedValue));
    }
    protected int[] TiaoxingDT = new int[49];
    /// <summary>
    /// 计算红篮球的出现个数
    /// </summary>
    /// <param name="type">0 红球 1 蓝球</param>
    /// <param name="data">对应球的号码</param>
    protected void bindTiaoxing(int type, int data)
    {
        for (int i = 0; i < 47; i++)
        {
            if (type == 0)
            {
                if (data == (i + 1))
                {
                    TiaoxingDT[i] += 1;
                }
            }
            if (type == 1)
            {
                if (data == (i + 1 - 35))
                {
                    TiaoxingDT[i] += 1;
                }
            }
        }
    }
    /// <summary>
    /// 计算尾数
    /// </summary>
    /// <param name="data">对应红球的号码</param>
    void bindWs(string[] redBall)
    {
        DataRow newRow = dtPaperList.NewRow();
        for (int m = 0; m < redBall.Length; m++)
        {
            int data = int.Parse(redBall[m].Substring(redBall[m].Length - 1, 1));
            for (int i = 0; i < 10; i++)
            {
                if (data == i)
                {
                    string aa = newRow["Hezhi" + i].ToString();
                    if (aa == "")
                    {
                        newRow["Hezhi" + i] = "0";
                    }
                    int a = int.Parse(newRow["Hezhi" + i].ToString());

                    newRow["Hezhi" + i] = (a + 1).ToString();

                }
            }
        }
        dtPaperList.Rows.Add(newRow);
    }
}